/*
 * XDoubleColumn.java
 * 
 * Copyright (c) 2006 - 2007
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.xfc.table;

import java.text.NumberFormat;

/**
 * 
 * 
 * @author Devon Carew
 */
public abstract class XDoubleColumn
	extends XTableColumn
{
	private NumberFormat nf;
	
	public XDoubleColumn(String columnName)
	{
		this(columnName, -1, -1);
	}
	
	public XDoubleColumn(String columnName, int minFractionDigits)
	{
		this(columnName, minFractionDigits, -1);
	}
	
	public XDoubleColumn(String columnName, int minFractionDigits, int maxFractionDigits)
	{
		super(columnName, Double.class);
		
		setCellRenderer(XTableRenderers.getDoubleRenderer(minFractionDigits, maxFractionDigits));
		
		nf = NumberFormat.getNumberInstance();
		
		if (minFractionDigits != -1)
			nf.setMinimumFractionDigits(minFractionDigits);
		
		if (maxFractionDigits != -1)
			nf.setMaximumFractionDigits(maxFractionDigits);
	}

	public String getFilterText(Object rowObject)
	{
		Double d = (Double)getValue(rowObject);
		
		if (d == null)
			return null;
		
		return nf.format(d);
	}
	
}
